package com.zl.tby.vo.bean;

import com.zl.tby.core.base.util.ToolsUtil;
import com.zl.tby.model.TbyAnimalPlant;
import lombok.Data;
import org.noear.wood.utils.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 物种图例
 * @author changpeng
 * @since 2025/10/28 15:12
 */
@Data
public class SpeciesLegendBean {
    /**主键id*/
    private Long id;
    /**物种名*/
    private String name;
    /**图片*/
    private String img;
    private String icon;
    /**坐标*/
    private List<Map<String, String>> pointList;

    public SpeciesLegendBean() {}

    public SpeciesLegendBean(TbyAnimalPlant entity) {
        this.setId(entity.getId());
        this.setName(entity.getChName());
        if (StringUtils.isNotEmpty(entity.getThumbnail())) {
            this.setImg(entity.getThumbnail());
        } else {
            this.setImg(entity.getFiles());
        }
        if (StringUtils.isNotEmpty(entity.getThumbnailIcon())) {
            this.setIcon(entity.getThumbnailIcon());
        } else if (StringUtils.isNotEmpty(entity.getThumbnail())) {
            this.setIcon(entity.getThumbnail());
        } else {
            this.setIcon(entity.getFiles());
        }
        String[] array = ToolsUtil.splitStr(entity.getLatitudeLongitude(), '@');
        List<Map<String, String>> points = new ArrayList<>();
        for (String s : array) {
            String[] point = ToolsUtil.splitStr(s, '&');
            Map<String, String> map = new HashMap<>();
            map.put("longitude", point[0]);
            map.put("latitude", point[1]);
            points.add(map);
        }
        this.setPointList(points);
    }
}
